package tianhao.luo.tree;

import lombok.Data;

/**
 * 二叉树
 *
 * @author: tianhao.luo@hand-china.com 2021/6/22  下午8:25
 */
public class BinaryTree {

    private  HeroNode root;

    public BinaryTree(HeroNode root) {
        this.root = root;
    }

    public void preOrder(){
        if (this.root !=null){
            this.root.preOrder();
        }else {
            System.out.println("二叉树为空");
        }
    }

    public void infixOrder(){
        if (this.root !=null){
            this.root.infixOrder();
        }else {
            System.out.println("二叉树为空");
        }
    }

    public void postOrder(){
        if (this.root !=null){
            this.root.postOrder();
        }else {
            System.out.println("二叉树为空");
        }
    }

    public HeroNode preOrderSearch(int no){
        if (this.root !=null){
            return this.root.preOrderSearch(no);
        }else {
            System.out.println("二叉树为空");
            return null;
        }
    }

    public HeroNode infixOrderSearch(int no){
        if (this.root !=null){
            return this.root.infixOrderSearch(no);
        }else {
            System.out.println("二叉树为空");
            return null;
        }
    }

    public HeroNode postOrderSearch(int no){
        if (this.root !=null){
            return this.root.postOrderSearch(no);
        }else {
            System.out.println("二叉树为空");
            return null;
        }
    }


    public void deleteNode(int no){
        if (root !=null){
            if (root.getNo() == no){
                root =null;
            }else {
                root.deleteNode(no);
            }
        }else {
            System.out.println("空树");
        }
    }
}
